package com.bruce.service;

import com.bruce.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public SysUser getSysUser(String userName,String password){
        List<Object> params = new ArrayList<Object>();
        String sql = "select * from sysuser where userName=? and password= ? ";
        params.add(userName);
        params.add(password);
        RowMapper<SysUser> rm = BeanPropertyRowMapper.newInstance(SysUser.class);
        SysUser model = jdbcTemplate.queryForObject(sql,params.toArray(),rm);
        return model;
    }

    public List<SysUser> getSysUserList(){
        String sql = "select * from sysuser ";
        RowMapper<SysUser> rm = BeanPropertyRowMapper.newInstance(SysUser.class);
        List<SysUser> list = jdbcTemplate.query(sql,rm);
        return list;
    }
}
